package com.sugree.util;

import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class PublicService {
	protected static final Pattern TWITPIC_PATTERN = Pattern.compile("https?://(www\\.)?(twitpic\\.com)/([a-zA-Z0-9]+)");
	protected static final Pattern TWITGOO_PATTERN = Pattern.compile("https?://(www\\.)?(twitgoo\\.com)/([a-zA-Z0-9]+)");
	protected static final Pattern IMGLY_PATTERN = Pattern.compile("https?://(www\\.)?(img\\.ly)/([a-zA-Z0-9]+)");
	protected static final Pattern YFROG_PATTERN = Pattern.compile("https?://(www\\.)?(yfrog\\.com)/([a-zA-Z0-9]+)");
	protected static final Pattern FLICKR_PATTERN = Pattern.compile("https?://(www\\.)?(flic\\.kr)/p/([a-zA-Z0-9]+)");
	protected static final Pattern TWEETPHOTO_PATTERN = Pattern.compile("https?://(www\\.)?(tweetphoto\\.com)/([0-9]+)");
	protected static final Pattern PLIXI_PATTERN = Pattern.compile("https?://(www\\.)?(plixi\\.com)/p/([0-9]+)");
	protected static final Pattern PICGD_PATTERN = Pattern.compile("https?://(www\\.)?(pic\\.gd)/([a-zA-Z0-9]+)");
	protected static final Pattern UPICME_PATTERN = Pattern.compile("https?://(www\\.)?(upic\\.me)/([a-zA-Z0-9]+)");
	protected static final Pattern MYLOC_PATTERN = Pattern.compile("https?://(www\\.)?(myloc\\.me)/([a-zA-Z0-9]+)");
	protected static final Pattern FOURSQ_PATTERN = Pattern.compile("https?://(www\\.)?(4sq\\.com)/([a-zA-Z0-9]+)");
	protected static final Pattern PICPLZ_PATTERN = Pattern.compile("https?://(www\\.)?(picplz\\.com)/([a-zA-Z0-9]+)");

	protected static final Pattern[] IMAGE_PATTERNS = new Pattern[] {
		TWITPIC_PATTERN,
		TWITGOO_PATTERN,
		IMGLY_PATTERN,
		YFROG_PATTERN,
		FLICKR_PATTERN,
		TWEETPHOTO_PATTERN,
		PLIXI_PATTERN,
		PICGD_PATTERN,
		UPICME_PATTERN,
		PICPLZ_PATTERN,
	};

	protected static final Pattern[] LOCATION_PATTERNS = new Pattern[] {
		MYLOC_PATTERN,
		FOURSQ_PATTERN,
	};

	public static boolean isImageService(String url) {
		for(int i=0; i<IMAGE_PATTERNS.length; i++) {
			Pattern p = IMAGE_PATTERNS[i];
			if (p.matcher(url).matches()) {
				return true;
			}
		}
		return false;
	}
}
